/*
 * XX公司源代码，版权归XX公司所有。
 * 
 * 项目名称 : it-ogt-kq-common
 * 创建日期 : 2024年1月23日
 * 修改历史 : 
 *     1. [2024年1月23日]创建文件 by huangwu
 */
package com.hyt.it.ogt.kq.common.utils;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;

/***
 * https://blog.csdn.net/weixin_44673447/article/details/133688295
 * //TODO 添加类/接口功能描述
 * @author huangwu
 */
public class PmsPriceSeaTemplateMergeStrategy implements RowWriteHandler {


    @Override
    public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer integer, Integer integer1, Boolean aBoolean) {

    }

    @Override
    public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer integer, Boolean aBoolean) {

    }

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer integer, Boolean aBoolean) {
        if (row.getRowNum() > 1) {
            return;
        }
        // 获取当前sheet
        Sheet sheet = writeSheetHolder.getSheet();

        titleHandle(sheet);

        titleHandle2(sheet);

    }

    private void titleHandle2(Sheet sheet) {

        Row row = sheet.getRow(1);

        if(null == row) {
            return;
        }

        row.setHeightInPoints(20);
    }

    private void titleHandle(Sheet sheet) {
        Workbook workbook = sheet.getWorkbook();
        Font font = workbook.createFont();

        CellStyle cellStyle = workbook.createCellStyle();
        // 内容靠左
        cellStyle.setAlignment(HorizontalAlignment.LEFT);
        cellStyle.setFont(font);
        // 是否换行
        cellStyle.setWrapText(true);
        
        

        Row row = sheet.getRow(0);
        for (int i = 0; i < 24; i++) {
            Cell cell0 = row.getCell(i);
            if(null == cell0) {
                continue;
            }
            cell0.setCellStyle(cellStyle);
        }

        // 设置字体大小
        row.setHeightInPoints(125);
        
        row.setHeightInPoints(60);
    }

}
